/***************************************************************************
 *   gmgpi.h - Graphic Routines Names Definition                           *
 *   Copyright (C) 2008 by cmaster.matso (Maciej Kadłubowski)              *
 *   cmaster.matso@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef _GMGPI_H
#define _GMGPI_H

#ifdef __cplusplus
extern "C" {
#endif

#include "g3dmdl/src/mgpi_roeskva.h"
    
    /* MGPI Engine (Roeskva) Properties & Macros */

#define MGPI_ENGINE_DEFINED  Roeskva_t g_ctx                                   /** engine rendering context macro */
#define MGPI_ENGINE_IMPLEMENT    engImplement(&g_ctx)                          /** engine interface implementation macro */
#ifndef WIN32
#define MGPI_ENGINE_ENTRY    int main(int argc,char*argv[])                     /** engine entry point macro (Linux, non-Windows) */
#define MGPI_ENGINE_PREINIT  glutInit(&argc, argv)                             /** engine preinitialization macro (Linux, non-Windows) */
#elif defined WIN32 && defined _WINDOWS
#define MGPI_ENGINE_ENTRY    int APIENTRY WinMain(HINSTANCE hInstance,\
					 HINSTANCE hPrevInstance,\
					 LPSTR lpCmdLine,\
					 int nCmdShow)                          /** engine entry point macro (Win32/64 window app.) */
#define MGPI_ENGINE_PREINIT  glutInit(&nCmdShow,(char **)&lpCmdLine);           /** engine preinitialization macro (Win32/64 window app.) */
#elif defined WIN32 && defined _CONSOLE
#define MGPI_ENGINE_ENTRY    int main(int argc,char*argv[])                     /** engine entry point macro (Windows console app.) */
#define MGPI_ENGINE_PREINIT  glutInit(&argc, argv);                             /** engine preinitialization macro (Windows console app.) */
#endif
#define MGPI_ENGINE_START    if(!engStart(ctx)){ENGINE_Exit();exit(EXIT_FAILURE);}              /** engine start macro */
#define MGPI_ENGINE_STOP    engStop(NULL)                                      /** engine stop macro */

    /**
     * A initialization function, called at the beginning of the application. In here
     * one can put any code concerning loading objects, preparing the scene etc.
     */
    void ENGINE_Init(Roeskva_t *node);

    /**
     * The engine main rendering loop function. Place here any code referring
     * to rendering process. Note that calling here any logic processing functions
     * is not advisable.
     */
    void ENGINE_Render(Roeskva_t *node);

#define MGPI_ENGINE_INIT ENGINE_Init(&g_ctx);                                       /** engine initialization macro */
#define MGPI_ENGINE_CREATE_CAMERA(type)  (ctx->hcamera=ctx->createCamera(type))     /** default engine camera creation macro */
#define MGPI_ENGINE_CREATE_SHADER(id,type,n,code,l) (id=ctx->setupShader(type,n,code,l))/** engine shader creation macro */
#define MGPI_ENGINE_SELECT_NEW_OBJECT(id,type,name) ctx->selectObject((id=ctx->loadObject(name,type)))/** select new object macro */
#define MGPI_ENGINE_CAMERA ctx->hcamera                                             /** default engine camera property */
#define MGPI_ENGINE_RENDER  while(MGPI_STATE)ENGINE_Render(&g_ctx)                 /** engine main rendering loop macro */
#define MGPI_ENGINE_RENDER_SINGLE  while(MGPI_Listener(MGPI_GetRootContainer()))ENGINE_Render(&g_ctx)
#define MGPI_ENGINE_PROPERTY ctx->setProperty										/** engine property access macro */
#define MGPI_EXIT_SUCCESS   {ENGINE_Exit();exit(EXIT_SUCCESS);}                                     /** successful exit */
#define MGPI_EXIT_FAILURE   {ENGINE_Exit();exit(EXIT_FAILURE);}                                     /** failed exit */

/** engine handles macros */
#define MGPI_ENGINE_HANDLE0		ctx->handles[0]
#define MGPI_ENGINE_HANDLE1		ctx->handles[1]
#define MGPI_ENGINE_HANDLE2		ctx->handles[2]
#define MGPI_ENGINE_HANDLE3		ctx->handles[3]
#define MGPI_ENGINE_HANDLE4		ctx->handles[4]
#define MGPI_ENGINE_HANDLE5		ctx->handles[5]
#define MGPI_ENGINE_HANDLE6		ctx->handles[6]
#define MGPI_ENGINE_HANDLE7		ctx->handles[7]
#define MGPI_ENGINE_HANDLE8		ctx->handles[8]
#define MGPI_ENGINE_HANDLE9		ctx->handles[9]
#define MGPI_ENGINE_HANDLE10	ctx->handles[10]
#define MGPI_ENGINE_HANDLE11	ctx->handles[11]
#define MGPI_ENGINE_HANDLE12	ctx->handles[12]
#define MGPI_ENGINE_HANDLE13	ctx->handles[13]
#define MGPI_ENGINE_HANDLE14	ctx->handles[14]
#define MGPI_ENGINE_HANDLE15	ctx->handles[15]
#define MGPI_ENGINE_HANDLE16	ctx->handles[16]
#define MGPI_ENGINE_HANDLE17	ctx->handles[17]
#define MGPI_ENGINE_HANDLE18	ctx->handles[18]
#define MGPI_ENGINE_HANDLE19	ctx->handles[19]
#define MGPI_ENGINE_HANDLE20	ctx->handles[20]
#define MGPI_ENGINE_HANDLE21	ctx->handles[21]
#define MGPI_ENGINE_HANDLE22	ctx->handles[22]
#define MGPI_ENGINE_HANDLE23	ctx->handles[23]
#define MGPI_ENGINE_HANDLE24	ctx->handles[24]
#define MGPI_ENGINE_HANDLE25	ctx->handles[25]
#define MGPI_ENGINE_HANDLE26	ctx->handles[26]
#define MGPI_ENGINE_HANDLE27	ctx->handles[27]
#define MGPI_ENGINE_HANDLE28	ctx->handles[28]
#define MGPI_ENGINE_HANDLE29	ctx->handles[29]
#define MGPI_ENGINE_HANDLE30	ctx->handles[30]
#define MGPI_ENGINE_HANDLE31	ctx->handles[31]

#define MGPI_ENGINE_HANDLES		ctx->handles

#ifdef __cplusplus
}
#endif

#endif
